package com.sweet.logging.logger;

import javax.naming.ConfigurationException;

/**
 *
 * 日志级别
 *
 * @author xiexiaofeng
 * @version 1.0     2017年09月08日  12点43分
 */
public enum LoggingLevel
{
    TRACE(-2, "TRACE"), DEBUG(-1, "DEBUG"), INFO(0, "INFO"), WARN(1, "WARN"), ERROR(2,"ERROR");

    LoggingLevel(int code, String name)
    {
        this.code = code;
        this.name = name;
    }

    private int code;

    private String name;

    public void setCode(int code)
    {
        this.code = code;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getCode()
    {
        return code;
    }

    public void setCode(short code)
    {
        this.code = code;
    }

    public static int getCodeByName(String name) throws ConfigurationException
    {
        switch (name)
        {
            case "TRACE" : return TRACE.getCode();
            case "DEBUG" : return DEBUG.getCode();
            case "INFO"  : return INFO.getCode();
            case "WARN"  : return WARN.getCode();
            case "ERROR" : return ERROR.getCode();
            default: throw new ConfigurationException("unknow log level named" + name);
        }
    }
}
